package com.cloud.dubbo.provider.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cloud.dubbo.api.dto.StockDto;
import com.cloud.dubbo.api.service.HelloService;
import com.cloud.dubbo.api.utils.ColaBeanUtils;
import com.cloud.dubbo.provider.entity.Stock;
import com.cloud.dubbo.provider.mapper.StockMapper;
import org.apache.dubbo.config.annotation.DubboService;


import javax.annotation.Resource;
import java.util.List;

//@org.apache.dubbo.config.annotation.Service 2.7.7 之前
@DubboService
public class HelloServiceImpl implements HelloService {
    @Resource
    StockMapper stockMapper;

    @Override
    public String hello() {
        return "hello  consumer";
    }

    /**
     * QueryWrapper 查询条件的分装
     * where  条件  >  and
     *
     * @param page
     * @param size
     * @return
     */
    @Override
    public List<StockDto> getStocks(Integer page, Integer size) {
        QueryWrapper<Stock> qw = new QueryWrapper<>();
//        qw.lambda().eq(Stock::getStatus, 1);
//        where  status= 1
        qw.eq(Stock.COL_STATUS, 1);
        Page<Stock> stockPage = stockMapper.selectPage(new Page<>(page, size), qw);
        List<Stock> records = stockPage.getRecords();
        //po对象转化成dto  BeanUtils
        return ColaBeanUtils.copyListProperties(records, StockDto::new);
    }
}
